home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / drdobbs / 1991 / 10 / smalltlk.asc < prev    next >
Text File  |  1991-09-10  |  2KB  |  88 lines

  1. _SMALLTALK AND EMBEDDED SYSTEMS_
  2. by John Duimovich and Mike Milinkovich
  3.  
  4. Example 1
  5.  
  6. (a)
  7.  
  8.  
  9.     checkSum
  10.         "Answer a twos complement checksum of the receiver."
  11.  
  12.         <primitive: checkSum>
  13.         ^ self primitiveFailed
  14.  
  15.  
  16. (b)
  17.  
  18.  
  19.     #include "userprim.h"
  20.     DEFINE_USER_PRIMITIVE( checkSum )
  21.     {
  22.         char *buffer;
  23.         unsigned int size;
  24.         unsigned short chkSum;
  25.         char *V_objectByteAddress();
  26.  
  27.         buffer = V_objectByteAddress(PARAM(1));
  28.         size = V_objectSize (PARAM (1));
  29.         for (i=0;i<size;i++) {
  30.                 chkSum += *buffer++;
  31.         }
  32.         SUCCEED (TO_SmallInteger(chkSum));
  33.      }
  34.  
  35.  
  36.  
  37.  
  38. Examplσ 2
  39.  
  40. (a)
  41.  
  42.  
  43.         while {1) {
  44.             wait_for_data();
  45.             if (enough_data) V_interruptVM (20);
  46.         }
  47.  
  48.  
  49. (b)
  50.  
  51.       Process 
  52.           configureInterrupt: 20 
  53.           withMessage: 
  54.               (DirectedMessage
  55.                   selector: #enoughDataHasArrived
  56.                   arguments: #()
  57.                   receiver: dataHandler).
  58.  
  59.  
  60. (c)
  61.  
  62.     enoughDataHasArrived
  63.         "Inform the process waiting for the data that the
  64.              data has arrived."
  65.  
  66.          dataFullSemaphore signal
  67.  
  68.  
  69. (d)
  70.  
  71.     [[true] whileTrue: [
  72.         dataFullSemaphore wait.
  73.         self processDataBuffer]] forkAt: 2
  74.  
  75.  
  76.  
  77.  
  78. Examplσ 3
  79.  
  80.     DEFINE_USER_PRIMITIVE(semaphoreSignal)
  81.     {
  82.         int semId; 
  83.         IF ISNOT_SmallInteger (PARAM (1)) THEN FAIL; ENDIF
  84.         semId = TO_long (PARAM (1));
  85.         semGive (semId);
  86.         SUCCEED (SELF);
  87.      }
  88.